package com.blink.zookeeper.operate;

import com.blink.base.TestZK;
import com.blink.zookeeper.ZooKeeperCreator;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.ZooKeeper;
import org.junit.jupiter.api.Test;

/**
 * <Description> 判断节点是否存在</Description>
 * <ClassName> TestZKExistsNode</ClassName>
 *
 * @Author liuxianzhao
 * @Date 2018年01月12日 14:47
 */
public class TestZKExistsNode extends TestZK {
    @Test
    public void testExistsNode() throws KeeperException, InterruptedException {
        String path = "/zk-book";
        ZooKeeper zk = ZooKeeperCreator.getZk("testExistsNode");
        zk.exists(path, true);
        zk.create(path, "".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        zk.setData(path, "123".getBytes(), -1);
        zk.create(path + "/c1", "".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        zk.exists(path, true);
        zk.delete(path + "/c1", -1);
        zk.delete(path, -1);
        Thread.sleep(Integer.MAX_VALUE);
    }
}
